<template>
	<view class="wrap">
		<view class="tab">
			<u-sticky bgColor="#fff">
				<u-tabs :list="list1" lineWidth="70" lineColor="#0C68FD"  @click="changeTab" :activeStyle="{
			    color: '#0C68FD',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)'
			}" :inactiveStyle="{
			    color: '#606266',
			    transform: 'scale(1)'
			}" itemStyle="padding-left: 45px; padding-right: 35px; height: 34px;"></u-tabs>
			</u-sticky>
		</view>
		
		<view class="list">
			<view v-for="(item,index) in list" @click="jump(item.id)">
				<view>
					<view>
						<view class="">
							<text>{{item.createtime}}</text>
						</view>
						<view class="list_body">
							<view class="list_content">
								<text>{{item.name}}</text>
								<text v-if="item.type==0">暂无</text>
								<text v-else-if="item.type==1">电访</text>
								<text v-else-if="item.type==2">面访</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="loadingText">{{loadingText}}</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				
				list: [],
				page: 1,
				loadingText: '',
				list1: [{
					name: '全部',
					id:0
				}, {
					name: '电访',
					id:1,
					
				}, {
					name: '面访',
					id:2
				} ],
				type:0,
				villager_id:''
				
			}
		},
		
		onPullDownRefresh() {
			this.page = 1
			this.getList();
		},
		onReachBottom() {
			this.loadingText = "--上拉显示更多--"
			this.getMoreList();
		},
		onLoad(option){
			this.villager_id = option.villager_id;
			this.list = [];
			this.page = 1;
			this.getList();
		},
	
		onShow() {
	          this.list = [];
	          this.page = 1;
	          this.getList();  
		},
		methods: {
		changeTab(item){
			console.log(item)
			this.type = item.id;
			this.list = [];
			this.page = 1
			this.getList();
		},
			
			getMoreList() {
				this.loadingText = '-- 正在加载 --'
				let obj = {};
				 obj.page=this.page;
				 obj.type = this.type;
				 obj.villager_id = this.villager_id;
				this.$api.post('/api/villagers/visitList',obj).then((res) => {
					if (res.code == 1) {
						this.info = res.data;
						if (res.data.list.length == 0 || res.data.list == null) {
							this.loadingText = '-- 暂无更多 --'
							return false;
						}
						var newlist = res.data.list;
						this.list = this.list.concat(newlist)
						this.page++
					} else {
						this.toastMsg(res.msg);
					}
				});
			},
			
			getList() {
				 let obj = {};
				 obj.page=this.page;
				  obj.type = this.type;
				   obj.villager_id = this.villager_id;
				this.$api.post('/api/villagers/visitList',obj).then((res) => {
					if (res.code == 1) {
						if (res.data.list.length == 0 || res.data.list == null) {
							this.loadingText = '-- 暂无更多 --'
							return false;
						}
						this.list = res.data.list;
						uni.stopPullDownRefresh()
						this.page++
					} else {
						this.toastMsg(res.msg);
					}
				})
			},
			jump(id){
				uni.navigateTo({
					url:'./history-detail?id='+id
				})
			}
			
		},
		
	}
</script>
<style>
	page {
		background-color: #EFF1F5;
	}
	/deep/.u-tabs__wrapper__nav__line{
		left: 44rpx;
	}
</style>
<style lang="scss">
	.tab{
		display: flex;
		justify-content: center;
		background-color: #fff;
	}
	.loadingText {
		padding: 20rpx 0 40rpx 0;
		text-align: center;
		color: #310D05;
		font-size: 28rpx;
	}
	.list {

		margin: 30rpx 30rpx;

		li {
			margin-left: -40rpx;
			margin-top: 30rpx;
		}
	}

	.list_body {
		background-color: #fff;
		margin: 20rpx 20rpx 20rpx 0;
		padding: 30rpx;
		border-radius: 20rpx;

		.list_content {
			display: flex;
			justify-content: space-between;

			text:first-child {
				color: #333333;
				font-size: 32rpx;
			}

			text:last-child {
				color: #999999;
				font-size: 28rpx;
			}
		}
	}
</style>
